<template>
<div class="home">
  <el-container>
  <el-aside width="auto">
    <div class="logo"></div>
     <!-- 第一步  绑定 :collapse="isCollapse"-->
    <el-menu
      router
      background-color= "#F9F9F9"
      :collapse="isCollapse"
      default-active="2"
      class="el-menu-admin"
      @open="handleOpen"
      @close="handleClose">
      <el-submenu index="1">
        <template slot="title">
          <i class="el-icon-location"></i>
          <span>用户管理</span>
        </template>
          <el-menu-item index="users">
             <i class="el-icon-menu"></i>
            <span slot="title">用户列表</span>
        </el-menu-item>
      </el-submenu>

      <el-submenu index="2">
        <template slot="title">
          <i class="el-icon-location"></i>
          <span>权限管理</span>
        </template>
          <el-menu-item index="Role">
             <i class="el-icon-menu"></i>
            <span slot="title">角色列表</span>
        </el-menu-item>
        <el-menu-item index="Rights">
             <i class="el-icon-menu"></i>
            <span slot="title">权限列表</span>
        </el-menu-item>
      </el-submenu>

       <el-submenu index="3">
        <template slot="title">
          <i class="el-icon-location"></i>
          <span>商品管理</span>
        </template>
          <el-menu-item index="goods">
             <i class="el-icon-menu"></i>
            <span slot="title">商品列表</span>
        </el-menu-item>
        <el-menu-item index="params">
             <i class="el-icon-menu"></i>
            <span slot="title">分类参数</span>
        </el-menu-item>
        <el-menu-item index="categories">
             <i class="el-icon-menu"></i>
            <span slot="title">商品分类</span>
        </el-menu-item>
      </el-submenu>
    </el-menu>
  </el-aside>

  <el-container>
    <el-header>
      <div class="myicon myicon-menu toggle-btn" @click='toggle'>

      </div>
      <div class="system-title">电商后台管理系统</div>
      <div>
        <span class="welcome">你好，{{username}}</span>
        <el-button type="warning" round @click="logout">退出</el-button>
      </div>
    </el-header>
    <el-main>
      <!-- mode="in-out" mode表示切换模式  只有两个值  一个in-out 一个 out-in-->
      <transition
        mode="in-out"
        enter-active-class="animated fadeIn"
        leave-active-class="animated fadeout"
      >
      <router-view></router-view>
      </transition>
    </el-main>
  </el-container>
</el-container>
</div>
</template>
<script>
// 引入Home
export default {
  data () {
    return {
      // 第二步
      isCollapse: false, // 默认为false  false为展开
      username: ''
    }
  },

  mounted () {
    let name = localStorage.getItem('username')
    this.username = name
  },
  methods: {
    // 第三步
    toggle () { // 点击的时候取反
      this.isCollapse = !this.isCollapse
    },
    // 退出：
    logout () {
      // 1.0清除本地token
      localStorage.removeItem('mytoken')
      // 2.0跳转登录页面
      this.$router.push({path: '/login'})
    },
    handleOpen (key, keyPath) {
      console.log(key, keyPath)
    },
    handleClose (key, keyPath) {
      console.log(key, keyPath)
    }
  }
}
</script>

<style lang="scss" scoped>
.home {
  height: 100%;
  .el-menu-admin:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
  }
  .el-container {
    height: 100%;
  }
  .el-aside {
    background-color: #F9F9F9;
  }
  .el-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #409EFF;
  }
  .logo {
    height:60px;
    background: url(../assets/logo.png);
    background-size: cover;
    background-color: white;
  }
  .toggle-btn {
    padding: 0 15px;
    margin-left: -20px;
    font-size: 36px;
    color: white;
    cursor: pointer;
    line-height: 60px;
    &:hover {
      background-color: #4292CF;
    }
  }
  .system-title {
    font-size: 28px;
    color: white;
  }
  .welcome {
    color: white;
  }
}
</style>
